import { Component, OnInit } from '@angular/core';
import { HttpRequest } from "../../../service/httpRequest";
import { flyIn } from '../../../animations/fly-in';

@Component({
  selector: 'app-modify-password',
  templateUrl: './modify-password.component.html',
  styleUrls: ['./modify-password.component.css'],
  animations: [
    flyIn
  ]
})
export class ModifyPasswordComponent implements OnInit {

  data:any;
  oldpassword:string = '';
  newpassword:string = '';
  confirmpassword:string = '';
  constructor(private httpRequest:HttpRequest) { }

  ngOnInit() {
    this.data = JSON.parse(localStorage.getItem('account'));
  }

  getData(){
    this.httpRequest.sendGet('account').subscribe(res => {
      this.data = res.result;
    },err => console.log(err))
  }

  modifypassword(){
    this.httpRequest.sendPut('account/modifypwd',{
      pwd: this.oldpassword,
      newpwd: this.newpassword,
      confirmPwd: this.confirmpassword
    }).subscribe(res => {
      if(res.resultStatus==202){
        alert(res.reason)
      }
      if(res.resultStatus==200){
        this.oldpassword = '';
        this.newpassword = '';
        this.confirmpassword = '';
        alert("密码修改成功,下次登录请使用新密码!")
      }
      if(res.resultStatus==201){
        alert(res.reason)
      }
    },err => console.log(err))
  }
}
